package com.hdoit.kylin.web.group.providers;

import java.util.ArrayList;
import java.util.List;

import com.hdoit.kylin.logical.group.model.Template;
import com.hdoit.kylin.logical.group.service.ITemplateService;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

public class TemplateProvider extends DataListProviderBase implements ISingleOptionListProvider<ListItem>{

	
	private List<Template> getTemplateList(){
		ITemplateService templateService = CommonApplicationContextUtil.getCurrentContext().getBean(ITemplateService.class);
		
		return templateService.queryList();
	}
	
	@Override
	public List<ListItem> getDataList(Object viewData){
		List<Template> templates = getTemplateList();
		if(templates==null || templates.size()<=0){
			return null;
		}
		dataList = new ArrayList<ListItem>();
		
		ListItem listItem = null;
		for(Template template : templates){
			listItem = new ListItem();
			listItem.setText(template.getTemplateName());
			listItem.setValue(template.getTemplateId());
			dataList.add(listItem);
		}
		return dataList;
	}
	
	
}
